Deduplicate raw MCP text envelope construction with shared helper#4352
Merged
Deduplicate raw MCP text envelope construction with shared helper#4352
Conversation
5 tasks
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/a3f06b05-31a7-402c-85b4-9fb0e879b2fc Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix duplicate code pattern in MCP text-content envelope construction
Deduplicate raw MCP text envelope construction with shared helper
Apr 22, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes construction of raw MCP “text” response envelopes to reduce duplication and drift risk across production call paths.
Changes:
- Added
mcp.BuildMCPTextResponse(text string)helper to build the canonical{content:[{type:"text",text:"..."}]}map shape. - Updated multiple server/proxy call sites to use the shared helper instead of inline map literals.
- Added a focused unit test validating the helper’s envelope structure and text passthrough.
Show a summary per file
| File | Description |
|---|---|
| internal/mcp/tool_result.go | Introduces the shared raw MCP text response envelope builder. |
| internal/mcp/tool_result_test.go | Adds unit coverage for BuildMCPTextResponse. |
| internal/server/unified.go | Replaces inline envelope construction with the shared helper for guard-facing permission calls. |
| internal/server/system_tools.go | Uses the shared helper for system tool text responses (sysInit, listServers). |
| internal/proxy/proxy.go | Uses the shared helper for proxy backend enrichment tool responses. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 0
This was referenced Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Raw MCP text-content envelopes (
{"content":[{"type":"text","text":"..."}]}) were being hand-constructed in multiple production paths, creating drift risk if the envelope shape changes. This PR centralizes that shape behind one helper and updates existing call sites to use it.Shared MCP response helper
mcp.BuildMCPTextResponse(text string) map[string]interface{}ininternal/mcp/tool_result.go.Call site consolidation
internal/server/unified.go(callCollaboratorPermission)internal/proxy/proxy.go(restBackendCaller)internal/server/system_tools.go(sysInit)internal/server/system_tools.go(listServers)Targeted unit coverage
TestBuildMCPTextResponseininternal/mcp/tool_result_test.goto validate envelope structure and text passthrough.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build3674478355/b509/launcher.test /tmp/go-build3674478355/b509/launcher.test -test.testlogfile=/tmp/go-build3674478355/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true rotocol/go-sdk@v1.5.0/internal/json/json.go -I x_amd64/vet --gdwarf-5 --64 ut-4038412272.c x_amd64/vet -I g_.a -fPIC x_amd64/vet -pthread go-sdk/oauthex -fmessage-length-bool x_amd64/vet(dns block)/tmp/go-build2111533505/b513/launcher.test /tmp/go-build2111533505/b513/launcher.test -test.testlogfile=/tmp/go-build2111533505/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build3674478355/b491/config.test /tmp/go-build3674478355/b491/config.test -test.testlogfile=/tmp/go-build3674478355/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true /internal/httpcommon/ascii.go /internal/httpcommon/headermap.go x_amd64/vet --gdwarf-5 ternal/engine/in-atomic -o x_amd64/vet 2897�� g_.a -I x_amd64/vet --gdwarf-5(dns block)/tmp/go-build2111533505/b495/config.test /tmp/go-build2111533505/b495/config.test -test.testlogfile=/tmp/go-build2111533505/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s 2897�� g_.a -goversion 64/pkg/tool/linux_amd64/vet -c=4 -nolocalimports -importcfg 64/pkg/tool/linux_amd64/vet -uns�� q62FCnbEi 64/pkg/tool/linu-I 64/pkg/tool/linux_amd64/vet g_.a amVETxCjQ ache/go/1.25.9/x--noprofile 64/pkg/tool/linux_amd64/vet(dns block)nonexistent.local/tmp/go-build3674478355/b509/launcher.test /tmp/go-build3674478355/b509/launcher.test -test.testlogfile=/tmp/go-build3674478355/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true rotocol/go-sdk@v1.5.0/internal/json/json.go -I x_amd64/vet --gdwarf-5 --64 ut-4038412272.c x_amd64/vet -I g_.a -fPIC x_amd64/vet -pthread go-sdk/oauthex -fmessage-length-bool x_amd64/vet(dns block)/tmp/go-build2111533505/b513/launcher.test /tmp/go-build2111533505/b513/launcher.test -test.testlogfile=/tmp/go-build2111533505/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s(dns block)slow.example.com/tmp/go-build3674478355/b509/launcher.test /tmp/go-build3674478355/b509/launcher.test -test.testlogfile=/tmp/go-build3674478355/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true rotocol/go-sdk@v1.5.0/internal/json/json.go -I x_amd64/vet --gdwarf-5 --64 ut-4038412272.c x_amd64/vet -I g_.a -fPIC x_amd64/vet -pthread go-sdk/oauthex -fmessage-length-bool x_amd64/vet(dns block)/tmp/go-build2111533505/b513/launcher.test /tmp/go-build2111533505/b513/launcher.test -test.testlogfile=/tmp/go-build2111533505/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s(dns block)this-host-does-not-exist-12345.com/tmp/go-build3674478355/b518/mcp.test /tmp/go-build3674478355/b518/mcp.test -test.testlogfile=/tmp/go-build3674478355/b518/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true olang.org/grpc@v1.80.0/internal/transport/bdp_estimator.go olang.org/grpc@v1.80.0/internal/transport/client_stream.go x_amd64/vet --gdwarf-5 g/grpc/metadata -o x_amd64/vet .cfg�� 2897549/b447/_pkg_.a -trimpath x_amd64/vet -p contextprotocol//usr/bin/runc -lang=go1.25 x_amd64/vet(dns block)/tmp/go-build3099190320/b253/mcp.test /tmp/go-build3099190320/b253/mcp.test -test.testlogfile=/tmp/go-build3099190320/b253/testlog.txt -test.paniconexit0 -test.timeout=10m0s(dns block)If you need me to access, download, or install something from one of these locations, you can either: